package cn.jiyun.function.controller;

import cn.jiyun.Result.Result;
import cn.jiyun.function.service.BackstageCountService;
import cn.jiyun.pojo.function.BackstageCount;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/count")
@Slf4j
public class BackstageCountController {

    @Autowired
    BackstageCountService backstageCountService;


    @PostMapping("/getCount")
    public Result getCount(@RequestBody BackstageCount backstageCount1) {
        List<BackstageCount> countList = backstageCountService.getCount(backstageCount1);
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (BackstageCount backstageCount : countList) {
            arrayList.add(Integer.parseInt(backstageCount.getCount()));
        }
        log.info("arrayList: {}", arrayList);
        log.info("countList: {}", countList);
        return Result.ok(arrayList);
    }

    @PostMapping("/getCount1")
    public Result getCount1(@RequestBody BackstageCount backstageCount1) {
        List<BackstageCount> countList = backstageCountService.getCount1(backstageCount1);
        ArrayList<LocalDate> arrayList = new ArrayList<>();
        for (BackstageCount backstageCount : countList) {
            arrayList.add(backstageCount.getDate());
        }
        log.info("arrayList: {}", arrayList);
        log.info("countList: {}", countList);
        return Result.ok(arrayList);
    }
}